import Cookies from 'js-cookie'

const TokenKey = 'hrsaas-ihrm-token'
const TimeStamp = 'hrsaas-TimeStamp'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function getTimeStamp() {
  return Cookies.get(TimeStamp)
}

export function setTimeStamp() {
  return Cookies.set(TimeStamp, Date.now())
}

export function transListToTreeData(list, value) {
  const arr = []
  list.forEach(item => {
    if (item.pid === value) {
      const child = transListToTreeData(list, item.id)
      if (child.length > 0) {
        item.children = child
      }
      arr.push(item)
    }
  })
  return arr
}
